#pragma once
#include "taskQueue.h"
#include <my_header.h>
typedef enum {
    SIGN_UP,
    SIGN_IN,
    CD,
    LS,
    PWD,
    MKDIR,
    REMOVE,
    PUTS,
    GETS,
    RMDIR
} cmd_t;

typedef struct cmdInfo_s {
    cmd_t cmd;
    char userName[100];
    char arg[100];
    int argLength;
    char fileName[100];
    off_t fileSize;
    char md5[100]; // 实际只需要32位，puts和gets文件时用
    char cmdPath[100];
    int user_id;
} cmdInfo_t;

typedef struct userInfo_s {
    char userName[100];
    char passWord[100];
} userInfo_t;

typedef struct train_s {
    int length;
    char data[4096];
} train_t;

typedef struct threadPool_s {
    int workerNum;
    pthread_t *tidArr;
    // 加队列
    taskQueue_t taskQueue;
} threadPool_t;
int makeWorker(threadPool_t *threadPool);
int epollAdd(int epfd, int fd);
int epollDel(int epfd, int fd);
int tcpInit(char *ip, char *port, int *psockfd);

// 配置文件相关函数
int configureInit_ip_port_threadNum(char *ip, char *port, char *threadNum);
int configureInit_mysql(char *user_name, char *psw);

// 向客户端返回0或-1
int sendYesOrNo(int netfd, const char *errinfo, int errinfoLen);

// 注册、登录相关函数
int recvLogIn(int netfd, cmdInfo_t *login, userInfo_t *user,
              MYSQL *mysql); // netfd不用传指针，复制一份就行
int signUp(int netfd, userInfo_t *user, MYSQL *mysql);
int signIn(int netfd, userInfo_t *user, MYSQL *mysql);
char *GenerateStr();

// mysql数据相关操作
MYSQL *mysqlInit(); // mySqlInit，和数据库初步建立连接
MYSQL_RES *mysqlSearch(char *sql, MYSQL *mysql);

// 服务端命令解析相关函数
int findCmdInterfaceServer(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int LS_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int CD_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int PUTS_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int GETS_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int REMOVE_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int PWD_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);
int MKDIR_Server(int netfd, cmdInfo_t *pcmdinfo, MYSQL *mysql);

//服务端transFile相关函数
int sendFile(int netfd, cmdInfo_t *cmdInfo);
int recvFile(int netfd, cmdInfo_t *cmdInfo);
int get_pre_id(cmdInfo_t *pcmdinfo, MYSQL *mysql);

//各种小火车
void recv_train(int netfd);
void send_train(int netfd, char buf[], int len);

void send_train001(int netfd, char buf[], int len);
